package com.example.shoppingdemo.nslcommodity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.shoppingdemo.R;
import com.example.shoppingdemo.nslcommodity.IResult.CommodityRs;
import com.example.shoppingdemo.nslcommodity.IResult.ICommodityResult;
import com.example.shoppingdemo.nslcommodity.adapter.OrderFormAdpater;
import com.example.shoppingdemo.nslcommodity.orderbean.ListModel;
import com.example.shoppingdemo.nslcommodity.orderbean.OrderModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单详情页面
 */
public class OrderForm extends AppCompatActivity {
    private TextView zMoney,freight,integration,discounts,
        payment,confirm,type,name,phone,address,numder,jifen,beizhu,time,xiugai;
    private ICommodityResult commodityResult;
    private RecyclerView orderlist;
    private OrderFormAdpater adpater;
    private List<ListModel> listModelList;
    int id;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_form);
        Intent intent=getIntent();
        id=intent.getIntExtra("id",-1);
        data();
        ImageView getBack=findViewById(R.id.image_back);
        initView();
        getBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    /**
     * 给view group赋值
     */
    private void data(){
        commodityResult=new CommodityRs(this);
    }
    private void initView(){
        xiugai=findViewById(R.id.text_order_form_xiugai);
        xiugai.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(OrderForm.this,CityActivity.class);
            startActivity(intent);
            }
        });
        type=findViewById(R.id.text_order_form_stous);
        name=findViewById(R.id.text_order_form_name);
        phone=findViewById(R.id.text_order_form_phone);
        address=findViewById(R.id.text_order_form_address);
        zMoney=findViewById(R.id.text_order_money);
        freight=findViewById(R.id.text_order_yufei);
        integration=findViewById(R.id.text_order_jifendikou);
        discounts=findViewById(R.id.text_order_youhuijuan);
        beizhu=findViewById(R.id.text_order_beizhu);
        payment=findViewById(R.id.text_order_xufukuan);
        confirm=findViewById(R.id.text_order_form_ok);
        orderlist=findViewById(R.id.order_form_recycler);
        numder=findViewById(R.id.text_order_sum);
        jifen=findViewById(R.id.text_order_form_kjifen);
        time=findViewById(R.id.text_order_time);
        listModelList=new ArrayList<>();
        orderlist.setLayoutManager(new LinearLayoutManager(this));
        adpater=new OrderFormAdpater(this);
        adpater.setOrderFormModels(listModelList);
        adpater.setOrderParticulars(new OrderFormAdpater.onOrderParticulars() {
            @Override
            public void onOrderResult(int position) {

            }
        });
        orderlist.setAdapter(adpater);
        commodityResult.onOrderForm(id,new CommodityRs.onOrderitemResponse() {
            @Override
            public void onOrderitemList(OrderModel orderModel) {
                switch (orderModel.getStatus()){
                    case 0:
                      type.setText("待付款");
                        break;
                    case 1:
                        type.setText("待发货");
                        break;
                    case 2:
                        type.setText("已发货");
                        break;
                    case 3:
                        type.setText("已完成");
                        break;
                    case 4:
                        type.setText("已关闭");
                        break;
                    case 5:
                        type.setText("无效订单");
                        break;
                }
                name.setText(orderModel.getReceiverName());
                phone.setText(orderModel.getReceiverPhone());
                address.setText(orderModel.getReceiverProvince()
                        +orderModel.getReceiverCity()
                        +orderModel.getReceiverRegion()
                +orderModel.getReceiverDetailAddress());
                zMoney.setText("￥"+orderModel.getTotalAmount());
                freight.setText("￥"+orderModel.getFreightAmount());
                integration.setText("￥"+orderModel.getIntegrationAmount());
                discounts.setText("￥"+orderModel.getCouponAmount());
                beizhu.setText(orderModel.getNote());
                payment.setText("￥"+orderModel.getPayAmount());
                numder.setText(orderModel.getOrderSn());
                jifen.setText("可获得"+orderModel.getIntegration()+"积分");
                time.setText(orderModel.getCreateTime());
                if (orderModel.getStatus()==0){
                    confirm.setText("确认付款");
                }else {
                    confirm.setText("加入购物车");
                }
                listModelList.clear();
                adpater.setOrderFormModels(orderModel.getListModels());
                adpater.notifyDataSetChanged();
            }
        });
        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

    }

}